<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>发放手持设卡</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link rel="stylesheet" type="text/css" href="../../css/style.css">
	<script type="text/javascript" src="../../js/jquery-1.8.2.js"></script>
	<script type="text/javascript" src="../../js/dialog/jquery.artDialog.source.js?skin=default"></script>
	<script type="text/javascript" src="../../js/dialog/plugins/iframeTools.source.js"></script>
	<script type="text/javascript" src="../../js/jquery.ztree.all-3.5.min.js"></script>
	<script type="text/javascript" src="../../js/jquery.form.js"></script>
	<script type="text/javascript" src="../../js/jquery.page.js"></script>
	<script type="text/javascript" src="../../js/base.js"></script>
</head>
<body class="app">
	<h3>发放手持卡</h3>
	<form class="search" name="search">
		<div class="tbdiv">
		<table>
			<tr>
				<th>用途：</th>
				<td><select name="cardUse" style="width:75px;"></select></td>
				<th>设备号：</th>
				<td><input name="cardNumber" type="text" class="inputText" ></select></td>
				<th>持有人姓名：</th>
				<td><input name="userName" type="text" class="inputText" ></select></td>
				<td align="right"><input type="submit" class="inputButton" value="查询"/></td>
			</tr>
		</table>
		</div>
	</form>
	<div id="list"></div>
	<div class="optionlink">
		<span id="btnUpd1">【设备发放】</span>
		<span id="btnUpd2">【设备转交】</span>
		<span id="btnUpd3">【设备回收】</span>
	</div>
	<div id="ffview" style="width:650px;display:none;">
		<form name="ffForm" action="ffscsb_save.action" method="post">
		<input type="hidden" name="indexId" />
		<dl class="view">
			<dt class="giant">设备号：</dt>
			<dd class="giant"><label name="cardNumber"></label><input type="hidden" name="cardNumber"/></dd>
			<dt class="giant">用途：</dt>
			<dd class="giant"><label name="cardUseText"></label></dd>
			<dt class="giant">设备版本：</dt>
			<dd class="giant"><input type="text" class="inputText" style="width:150px" name="cardEdition" /></dd>
			<dt class="giant">启用时间：</dt>
			<dd class="giant"><label name="cardUseDate"></label></dd>
			<dt class="giant">所属机构：</dt>
			<dd class="giant"><label name="agencyTypeText"></label></dd>
			<dt class="giant">所属单位：</dt>
			<dd class="giant"><label name="unitName"></label></dd>
			<dt class="giant">持有人姓名：</dt>
			<dd class="giant"><select name="serUserCode"></select></dd>
			<div class="cl"></div>
		</dl>
		</form>
	</div>
	<div id="zjview" style="width:650px;display:none;">
		<form name="zjForm" action="ffscsb_zjsave.action" method="post">
		<input type="hidden" name="indexId" />
		<dl class="view">
			<dt class="giant">设备号：</dt>
			<dd class="giant"><label name="cardNumber"></label><input type="hidden" name="cardNumber"/></dd>
			<dt class="giant">用途：</dt>
			<dd class="giant"><label name="cardUseText"></label></dd>
			<dt class="giant">设备版本：</dt>
			<dd class="giant"><input type="text" class="inputText" style="width:150px" name="cardEdition" /></dd>
			<dt class="giant">启用时间：</dt>
			<dd class="giant"><label name="cardUseDate"></label></dd>
			<dt class="giant">所属机构：</dt>
			<dd class="giant"><label name="agencyTypeText"></label></dd>
			<dt class="giant">所属单位：</dt>
			<dd class="giant"><label name="unitName"></label></dd>
			<dt class="giant">原持有人：</dt>
			<dd class="giant"><label name="userName"></label></dd>
			<dt class="giant">持有人姓名：</dt>
			<dd class="giant"><select name="serUserCode"></select></dd>
			<div class="cl"></div>
		</dl>
		</form>
	</div>
	<script type="text/javascript">
	$(function(){
		$(document.search).ajaxForm({
			beforeSubmit:function(formData){
				var param = $(formData).formParam();
				$('#list').page('param',param);
				$('#list').page('show');
				return false;
			}
		});
		$(document.ffForm).ajaxForm({
			success:function(response){
				var param = $(document.search).formParam();
				$('#list').page('param',param);
				$('#list').page('show');
				$('#list').data('checked').length = 0;
			}
		});
		$(document.zjForm).ajaxForm({
			success:function(response){
				var param = $(document.search).formParam();
				$('#list').page('param',param);
				$('#list').page('show');
				$('#list').data('checked').length = 0;
			}
		});
		//分页列表
		$('#list').page({
			url:'ffscsb_search.action',
			config:'pageinfo,record,first,last,next,prev,jump',
			items:[{
				name:'indexId',
				type:'checkbox',
				width:13
			},{
				title:'设备号',
				name:'cardNumber'
			},{
				title:'用途',
				name:'cardUseText'
			},{
				title:'所属单位',
				name:'unitCode',
				irender:function(row){
					if(row.adminName!=null){
						return row.adminName;
					}
					if(row.propertyName!=null){
						return row.propertyName;
					}
					if(row.serviceName!=null){
						return row.serviceName;
					}
				}
			},{
				title:'持有人姓名',
				name:'unitCode',
				irender:function(row){
					if(row.adminUserName!=null){
						return row.adminUserName;
					}
					if(row.proUserName!=null){
						return row.proUserName;
					}
					if(row.serUserName!=null){
						return row.serUserName;
					}
					return '暂无';
				}
			}]
		});
		$('#btnUpd1').click(function(){
			var ids = $('#list').data('checked');
			if(ids.length != 1){
				$.dialog.alert('一次只能对一个设备发放');
			}else{
				var list = $('#list').data('list');
				$.each(list,function(i,row){
					if(row.indexId == ids[0]){
						if(row.adminName!=null){
							row['unitName'] = row.adminName;
						}
						if(row.propertyName!=null){
							row['unitName'] = row.propertyName;
						}
						if(row.serviceName!=null){
							row['unitName'] = row.serviceName;
						}
						if(row.serUserCode!=null){
							$.dialog.alert('此设备已发放过！');
						}else{
							ffview(row);
						}
					}
				});
			}
		});
		$('#btnUpd2').click(function(){
			var ids = $('#list').data('checked');
			if(ids.length != 1){
				$.dialog.alert('一次只能对一个设备进行操作');
			}else{
				var list = $('#list').data('list');
				$.each(list,function(i,row){
					if(row.indexId == ids[0]){
						if(row.adminName!=null){
							row['unitName'] = row.adminName;
						}
						if(row.propertyName!=null){
							row['unitName'] = row.propertyName;
						}
						if(row.serviceName!=null){
							row['unitName'] = row.serviceName;
						}
						if(row.adminUserName!=null){
							row['userName'] = row.adminUserName;
						}
						if(row.proUserName!=null){
							row['userName'] = row.proUserName;
						}
						if(row.serUserName!=null){
							row['userName'] = row.serUserName;
						}
						if(row.serUserCode==null){
							$.dialog.alert('此设备未发放过！');
						}else{
							zjview(row);
						}
					}
				});
			}
		});
		$('#btnUpd3').click(function(){
			$.dialog.confirm('您确认回收所选设备吗？',function(){
				var ids = $('#list').data('checked').join(',');
				$.post('ffscsb_upd.action',{ids:ids},function(response){
					$('#list').page('show',1);
					$('#list').data('checked').length = 0;
				});
			});
		});
	});

	$(function(){
		//绑定行政监管单位
		$('select[name=cardUse]').selectload('../../common/code.action','code','codedesc',{codepid:'50'});
	})
	
	var ffview = function(row){
		$(document.ffForm).resetForm();
		$(document.ffForm.indexId).val('');
		$.dialog({
			id:'viewdialog',
			title:'信息查看-基本信息维护',
			lock:true,
			width:'100%',
			height:'100%',
			padding:'5px 8px 5px 5px',
			content:document.getElementById('ffview'),
			button:[{
				name:"保存",
				focus:true,
				callback:function(){
					$(document.ffForm).submit();
				}
			}]
		});
		switch (row.agencyType) {
			case '1':
				$('select[name=serUserCode]').selectload('../../common/adminuser_select.action','adminUserCode','adminUserName',{adminUserNowUnit:row.unitCode},false);
				break;
			case '2':
				$('select[name=serUserCode]').selectload('../../common/propertyuser_select.action','proUserCode','proUserName',{propertyCode:row.unitCode},false);
				break;
			case '3':
				$('select[name=serUserCode]').selectload('../../common/serviceuser_select.action','serUserCode','serUserName',{serviceCode:row.unitCode},false);
				break;
			default:
				$('select[name=serUserCode]').html('<option value="">-请选择-</option>')
				break;
		}
		$(document.ffForm).json2form(row);
	}
	var zjview = function(row){
		$(document.zjForm).resetForm();
		$(document.zjForm.indexId).val('');
		$.dialog({
			id:'viewdialog2',
			title:'手持卡维护',
			lock:true,
			width:'100%',
			height:'100%',
			padding:'5px 8px 5px 5px',
			content:document.getElementById('zjview'),
			button:[{
				name:"保存",
				focus:true,
				callback:function(){
					$(document.zjForm).submit();
				}
			}]
		});
		switch (row.agencyType) {
			case '1':
				$('select[name=serUserCode]').selectload('../../common/adminuser_select.action','adminUserCode','adminUserName',{adminUserNowUnit:row.unitCode},false);
				break;
			case '2':
				$('select[name=serUserCode]').selectload('../../common/propertyuser_select.action','proUserCode','proUserName',{propertyCode:row.unitCode},false);
				break;
			case '3':
				$('select[name=serUserCode]').selectload('../../common/serviceuser_select.action','serUserCode','serUserName',{serviceCode:row.unitCode},false);
				break;
			default:
				$('select[name=serUserCode]').html('<option value="">-请选择-</option>')
				break;
		}
		$(document.zjForm).json2form(row);
	}
	</script>
</body>
</html>
